package com.tdtxdcxm.ruralcommunity.slice;

import com.tdtxdcxm.ruralcommunity.ResourceTable;
import com.tdtxdcxm.ruralcommunity.appruntime.DataCenterControl;
import com.tdtxdcxm.ruralcommunity.myutils.MyTools;
import com.tdtxdcxm.ruralcommunity.providers.LCProviderForContent;
import com.tdtxdcxm.ruralcommunity.providers.LCProviderForNormal;
import com.tdtxdcxm.ruralcommunity.providers.PSProvider;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;

public class MainAbilitySlice extends AbilitySlice {
    public Boolean toanotherslice = false;

    private Boolean[] worlddownonce = {false,false,false};
    private Boolean[] worldfieldonce = {false,false,false,false,false,false,false};
    private Boolean[] messageonce = {false,false,false};

    private final String[] bottomTabNames = {"首页","领域","➕","消息","我的"};
    private final String[] firstCenterTabNames = {"动态","项目","文章"};
    private final String[] secondCenterTabNames = {"艺","衣","食","住","行","学","文"};
    private final String[] fourthCenterTabNames = {"通知","点赞","评论","收藏"};

    private DirectionalLayout deepdl,deepdl_topdl,deepdl_centerdl,deepdl_bottomdl;
    private DirectionalLayout surfacedl;
    private DirectionalLayout surfacedl_writeselect;

    private TabList deepdl_bottomdl_tablist;

    private Button dt_but,xm_but,wz_but;

    /*<-----------------------------------------安装顶部子布局区域-----------------------------------*/
    public void installSearchBar(){
        //安装搜索栏——将搜索栏安装到首页的顶部区域
        final int[] deepdl_topdl_height = {0};
        final boolean[] iskeyboarduse = {false};
        if(deepdl_topdl == null){
            return;
        }
        if(deepdl_topdl.getChildCount() != 0){
            deepdl_topdl.removeAllComponents();
        }
        DirectionalLayout searchbar_rootdl = (DirectionalLayout) LayoutScatter
                                            .getInstance(this.getContext())
                                            .parse(ResourceTable.Layout_searchbar,null,true);
        TextField searchtextField = (TextField) searchbar_rootdl.getComponentAt(0);
        Text searchGo = (Text) searchbar_rootdl.getComponentAt(1);

        searchtextField.addTextObserver(new Text.TextObserver() {
            @Override
            public void onTextUpdated(String s, int i, int i1, int i2) {

            }
        });
        searchGo.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                searchtextField.clearFocus();
                present(new PeopleListSlice(),new Intent().setParam("objectname", searchtextField.getText()));
                searchtextField.setText("");
            }
        });
        deepdl_topdl.setLayoutRefreshedListener(new Component.LayoutRefreshedListener() {
            @Override
            public void onRefreshed(Component component) {
                if(deepdl_topdl_height[0] == 0){
                    deepdl_topdl_height[0] = deepdl_topdl.getHeight();
                    return;
                }
                if(deepdl_topdl.getHeight() < deepdl_topdl_height[0]){
                    iskeyboarduse[0] = true;
                }
                if(deepdl_topdl.getHeight() == deepdl_topdl_height[0] && iskeyboarduse[0]){
                    searchtextField.clearFocus();
                    iskeyboarduse[0] = false;
                }
            }
        });
        deepdl_topdl.addComponent(searchbar_rootdl);
    }
    public void installTitleBar(String titleName){
        //安装标题栏——当底部导航栏切换到领域、消息、我的时安装，只安装一次，只需更改title文字内容即可
        if(deepdl_topdl == null){
            return;
        }
        if(deepdl_topdl.getChildCount() != 0){
            DirectionalLayout topsublayout_rootdl = (DirectionalLayout) deepdl_topdl.getComponentAt(0);
            if(topsublayout_rootdl.getChildCount() == 2){
                deepdl_topdl.removeAllComponents();
            }
            else{
                ((Text) topsublayout_rootdl.getComponentAt(0)).setText(titleName);
                return;
            }
        }
        DirectionalLayout titlebar_rootdl = (DirectionalLayout) LayoutScatter
                                            .getInstance(this.getContext())
                                            .parse(ResourceTable.Layout_main_titlebar,null,false);
        ((Text) titlebar_rootdl.getComponentAt(0)).setText(titleName);
        deepdl_topdl.addComponent(titlebar_rootdl);
    }
    public void installTopSubLayout(TabList.Tab tab){
        //安装顶部区域子布局
        switch (tab.getPosition()){
            case 0:
                installSearchBar();
                return;
            case 1:
            case 3:
            case 4:
                installTitleBar(tab.getText());
                return;
            default:
                return;
        }
    }
    /*------------------------------------------安装顶部子布局区域---------------------------------->*/

    /*<-----------------------------------------安装中部子布局区域-----------------------------------*/
    public Component installCenterSubLayout(TabList.Tab tab){
        //安装中间区域子布局
        //0-首页，1-L领域，2-➕，3-消息，4-我的
        if(deepdl_centerdl == null){
            return null;
        }
        if(deepdl_centerdl.getChildCount() != 0){
            deepdl_centerdl.removeAllComponents();
        }
        switch (tab.getPosition()){
            case 0:
                DirectionalLayout firstpage_center_rootdl = (DirectionalLayout) LayoutScatter
                                                            .getInstance(this.getContext())
                                                            .parse(ResourceTable.Layout_firstpage_center,null,false);
                deepdl_centerdl.addComponent(firstpage_center_rootdl);
                return firstpage_center_rootdl;
            case 1:
                DirectionalLayout secondpage_center_rootdl = (DirectionalLayout) LayoutScatter
                                                            .getInstance(this.getContext())
                                                            .parse(ResourceTable.Layout_firstpage_center,null,false);
                deepdl_centerdl.addComponent(secondpage_center_rootdl);
                return secondpage_center_rootdl;
            case 2:
                //这是bottomtablist的“+”位置，不做安装中间布局的处理
                return null;

            case 3:
                DirectionalLayout fourthpage_center_rootdl = (DirectionalLayout) LayoutScatter
                                                            .getInstance(this.getContext())
                                                            .parse(ResourceTable.Layout_fourthpage_center,null,false);
                deepdl_centerdl.addComponent(fourthpage_center_rootdl);
                return fourthpage_center_rootdl;
            case 4:
                DirectionalLayout fifthhpage_center_rootdl = (DirectionalLayout) LayoutScatter
                        .getInstance(this.getContext())
                        .parse(ResourceTable.Layout_fifhpage_center,null,false);
                deepdl_centerdl.addComponent(fifthhpage_center_rootdl);
                return fifthhpage_center_rootdl;
            default:
                return null;
        }
    }
    /*------------------------------------------安装中部子布局区域---------------------------------->*/

    /*<-----------------------------------------初始化PageSlider区域-----------------------------------*/
    private void initPageSlider(PageSlider pageSlider,PageSliderProvider pageSliderProvider,TabList bindTabList){
        if(pageSlider == null){return;}
        pageSlider.setPageCacheSize(3);
        pageSlider.setPageSwitchTime(50);
        pageSlider.setReboundEffect(true);
        pageSlider.setSlidingPossible(true);
        if(pageSliderProvider != null){
            pageSlider.setProvider(pageSliderProvider);
        }
        pageSlider.addPageChangedListener(new PageSlider.PageChangedListener() {
            @Override
            public void onPageSliding(int i, float v, int i1) {

            }

            @Override
            public void onPageSlideStateChanged(int i) {

            }

            @Override
            public void onPageChosen(int i) {
                if(bindTabList != null){
                    bindTabList.selectTabAt(i);
                }
                assert bindTabList != null;
                if(bindTabList.getName().equals("firstCenterTabList")){
                    switch (i) {
                        case 0:
                            if(worlddownonce[0]){
                                worlddownonce[0] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worlddt","");
                                worlddownonce[0] = true;
                            }
                            break;
                        case 1:
                            if(worlddownonce[1]){
                                worlddownonce[1] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldxm","");
                                worlddownonce[1] = true;
                            }
                            break;
                        case 2:
                            if(worlddownonce[2]){
                                worlddownonce[2] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldwz","");
                                worlddownonce[2] = true;
                            }
                            break;
                        default:
                            break;
                    }
                }
                if(bindTabList.getName().equals("secondCenterTabList")){
                    switch (i) {
                        case 0:
                            if(worldfieldonce[0]){
                                worldfieldonce[0] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","art");
                                worldfieldonce[0] = true;
                            }
                            break;
                        case 1:
                            if(worldfieldonce[1]){
                                worldfieldonce[1] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","clothe");
                                worldfieldonce[1] = true;
                            }
                            break;
                        case 2:
                            if(worldfieldonce[2]){
                                worldfieldonce[2] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","food");
                                worldfieldonce[2] = true;
                            }
                            break;
                        case 3:
                            if(worldfieldonce[3]){
                                worldfieldonce[3] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","house");
                                worldfieldonce[3] = true;
                            }
                            break;
                        case 4:
                            if(worldfieldonce[4]){
                                worldfieldonce[4] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","traffic");
                                worldfieldonce[4] = true;
                            }
                            break;
                        case 5:
                            if(worldfieldonce[5]){
                                worldfieldonce[5] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","study");
                                worldfieldonce[5] = true;
                            }
                            break;
                        case 6:
                            if(worldfieldonce[6]){
                                worldfieldonce[6] = false;
                            }
                            else{
                                MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","culture");
                                worldfieldonce[6] = true;
                            }
                            break;
                        default:
                            break;
                    }
                }
                if(bindTabList.getName().equals("fourthCenterTabList")){
                    switch(i){
                        case 0:
                            MyTools.toastShow("通知加载中...",MainAbilitySlice.this.getContext());
                            DataCenterControl.webView.load(DataCenterControl.messageNoticeUrlString);
                            break;
                        case 1:
                            if(messageonce[0]){
                                messageonce[0] = false;
                            }
                            else{
                                MyTools.DownDataMessageListInfo(MainAbilitySlice.this,"messageagree");
                                messageonce[0] = true;
                            }
                            break;
                        case 2:
                            if(messageonce[1]){
                                messageonce[1] = false;
                            }
                            else{
                                MyTools.DownDataMessageListInfo(MainAbilitySlice.this,"messagediscuss");
                                messageonce[1] = true;
                            }
                            break;
                        case 3:
                            if(messageonce[2]){
                                messageonce[2] = false;
                            }
                            else{
                                MyTools.DownDataMessageListInfo(MainAbilitySlice.this,"messagecollect");
                                messageonce[2] = true;
                            }
                            break;
                        default:
                            break;
                    }
                }

            }
        });
        if(pageSlider.getChildCount() != 0){
            pageSlider.setCurrentPage(0,true);
        }
    }
    /*------------------------------------------初始化PageSlider区域---------------------------------->*/

    /*<-----------------------------------------初始化TabList区域-----------------------------------*/
    private void addTabToTabList(TabList tabList,String tabName,String tabListName){
        //向某个TabList组件中添加一个tab,设置该tab名称
        if(tabList == null){
            return;
        }
        TabList.Tab tab = tabList.new Tab(this.getContext());
        tab.setText(tabName);
        tabList.addTab(tab);
    }
    private void initTabList(TabList tabList, String[] tabNames, String tabListName, PageSlider bindPageSlider){
        //初始化TabList————向里面添加多个tab，并对该tablist设置选择监听器
        if(tabList == null){
            return;
        }
        if(tabList.getTabCount() != 0){
            tabList.removeAllComponents();
        }
        tabList.setName(tabListName);
        for(int i = 0;i < tabNames.length;i++){
            addTabToTabList(tabList,tabNames[i],tabListName);
        }
        tabList.addTabSelectedListener(new TabList.TabSelectedListener() {
            @Override
            public void onSelected(TabList.Tab tab) {
                switch(tabList.getName()){
                    case "mainBottomTablist":
                        ShapeElement shapeElement = new ShapeElement();
                        shapeElement.setRgbColor(new RgbColor(238,149,114));
                        shapeElement.setCornerRadius(35);
                        tab.setBackground(shapeElement);

                        installTopSubLayout(tab);//如果是首页，则安装搜索栏，其余位安装标题栏
                        Component component = installCenterSubLayout(tab);//根据底部的tab安装相应的中间子布局

                        switch(tab.getPosition()){
                            case 0:
                                for(int i = 0;i < worlddownonce.length;i++){
                                    worlddownonce[i] = false;
                                }
                                DataCenterControl.webView = null;
                                //当切换到首页时，初始化中间区域的tablist
                                TabList firstpage_center_rootdl_tablist = (TabList) ((DirectionalLayout) component).getComponentAt(0);
                                PageSlider firstpage_center_rootdl_PageSlider = (PageSlider) ((DirectionalLayout) component).getComponentAt(1);

                                initPageSlider(firstpage_center_rootdl_PageSlider,
                                        new PSProvider(MainAbilitySlice.this, DataCenterControl.firstcenter_pageslist,firstCenterTabNames.length,0),
                                        firstpage_center_rootdl_tablist);
                                initTabList(firstpage_center_rootdl_tablist,
                                        firstCenterTabNames,
                                        "firstCenterTabList",
                                        firstpage_center_rootdl_PageSlider);
                                break;
                            case 1:
                                DataCenterControl.webView = null;
                                //当切换到领域时，初始化中间区域的tablist
                                TabList secondpage_center_rootdl_tablist = (TabList) ((DirectionalLayout) component).getComponentAt(0);
                                PageSlider secondpage_center_rootdl_PageSlider = (PageSlider) ((DirectionalLayout) component).getComponentAt(1);
                                initPageSlider(secondpage_center_rootdl_PageSlider,
                                        new PSProvider(MainAbilitySlice.this, DataCenterControl.secondcenter_pageslist,secondCenterTabNames.length,1),
                                        secondpage_center_rootdl_tablist);
                                initTabList(secondpage_center_rootdl_tablist,
                                        secondCenterTabNames,
                                        "secondCenterTabList",
                                        secondpage_center_rootdl_PageSlider);
                                break;
                            case 2:
                                break;
                            case 3:
                                //当切换到消息时，初始化中间区域的tablist
                                TabList fourthpage_center_rootdl_tablist = (TabList) ((DirectionalLayout) component).getComponentAt(0);
                                PageSlider fourthpage_center_rootdl_PageSlider = (PageSlider) ((DirectionalLayout) component).getComponentAt(1);
                                initPageSlider(fourthpage_center_rootdl_PageSlider,
                                        new PSProvider(MainAbilitySlice.this, DataCenterControl.fourthcenter_pageslist,fourthCenterTabNames.length,3),
                                        fourthpage_center_rootdl_tablist);
                                initTabList(fourthpage_center_rootdl_tablist,
                                        fourthCenterTabNames,
                                        "fourthCenterTabList",
                                        fourthpage_center_rootdl_PageSlider);
                                if(DataCenterControl.webView != null){}
                                break;
                            case 4:
                                //切换到我的
                                DataCenterControl.webView = null;
                                DirectionalLayout fifthhpage_center_rootdl = (DirectionalLayout) component;

                                DirectionalLayout follow_dl = (DirectionalLayout) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_follow_dl);
                                DirectionalLayout fans_dl = (DirectionalLayout) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_fans_dl);
                                DirectionalLayout dtlist_dl = (DirectionalLayout) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_dtlist_dl);
                                DirectionalLayout xmlist_dl = (DirectionalLayout)  fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_xmlist_dl);
                                DirectionalLayout wzlist_dl = (DirectionalLayout)  fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_wzlist_dl);
                                DirectionalLayout collectlist_dl = (DirectionalLayout)  fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_collectlist_dl);
                                DirectionalLayout about_dl = (DirectionalLayout) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_about_dl);

                                Text username_text = (Text) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_username_text);
                                Text follow_text = (Text) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_follow_text);
                                Text fans_text = (Text) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_fans_text);
                                Text readvalue_text = (Text) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_readvalue_text);
                                Text age_text = (Text) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_age_text);
                                Text gender_text = (Text) fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_gender_text);

                                username_text.setText(DataCenterControl.userName);
                                age_text.setText(DataCenterControl.age);
                                gender_text.setText(DataCenterControl.gender);

                                Text[] followfansread = {follow_text,fans_text,readvalue_text};
                                MyTools.DownDataFollowFansReadvalueInfo(MainAbilitySlice.this,DataCenterControl.userName,followfansread);

                                follow_dl.setClickedListener(new Component.ClickedListener() {
                                    @Override
                                    public void onClick(Component component) {
                                        present(new FollowAndFansListSlice(),new Intent().setParam("type","followlist"));
                                    }
                                });
                                fans_dl.setClickedListener(new Component.ClickedListener() {
                                    @Override
                                    public void onClick(Component component) {
                                        present(new FollowAndFansListSlice(),new Intent().setParam("type","fanslist"));
                                    }
                                });
                                dtlist_dl.setClickedListener(new Component.ClickedListener() {
                                    @Override
                                    public void onClick(Component component) {
                                        present(new UserContentListSlice(),new Intent().setParam("type","dtlist"));
                                    }
                                });
                                xmlist_dl.setClickedListener(new Component.ClickedListener() {
                                    @Override
                                    public void onClick(Component component) {
                                        present(new UserContentListSlice(),new Intent().setParam("type","xmlist"));
                                    }
                                });
                                wzlist_dl.setClickedListener(new Component.ClickedListener() {
                                    @Override
                                    public void onClick(Component component) {
                                        present(new UserContentListSlice(),new Intent().setParam("type","wzlist"));
                                    }
                                });
                                collectlist_dl.setClickedListener(new Component.ClickedListener() {
                                    @Override
                                    public void onClick(Component component) {
                                        present(new UserContentListSlice(),new Intent().setParam("type","collectlist"));
                                    }
                                });
                                fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_quit_dl)
                                        .setClickedListener(new Component.ClickedListener() {
                                            @Override
                                            public void onClick(Component component) {
                                                        DataCenterControl.messageagree_listcontainer_list.clear();
                                                        DataCenterControl.messagediscuss_listcontainer_list.clear();
                                                        DataCenterControl.messagecollect_listcontainer_list.clear();
                                                        DataCenterControl.userdt_listcontainer_list.clear();
                                                        DataCenterControl.userxm_listcontainer_list.clear();
                                                        DataCenterControl.userwz_listcontainer_list.clear();
                                                        DataCenterControl.usercollect_listcontainer_list.clear();
                                                        present(new StartPage(),new Intent());
                                                        terminate();
                                                    }
                                        });
                                fifthhpage_center_rootdl.findComponentById(ResourceTable.Id_destory_dl)
                                        .setClickedListener(new Component.ClickedListener() {
                                            @Override
                                            public void onClick(Component component) {
                                                MyTools.commonDialogRemoveShow("账号销毁提醒"
                                                                                ,"确认销毁账号？"
                                                                                ,component
                                                                                ,-1
                                                                                ,MainAbilitySlice.this
                                                                                ,"destory");
                                            }
                                        });
                                about_dl.setClickedListener(new Component.ClickedListener() {
                                    @Override
                                    public void onClick(Component component) {
                                        present(new AboutDetails(),new Intent());
                                    }
                                });
                                break;
                            default:
                                break;
                        }
                        break;
                    case "firstCenterTabList":
                        switch (tab.getPosition()) {
                            case 0:
                                if(worlddownonce[0]){
                                    worlddownonce[0] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worlddt","");
                                    worlddownonce[0] = true;
                                }
                                break;
                            case 1:
                                if(worlddownonce[1]){
                                    worlddownonce[1] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldxm","");
                                    worlddownonce[1] = true;
                                }
                                break;
                            case 2:
                                if(worlddownonce[2]){
                                    worlddownonce[2] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldwz","");
                                    worlddownonce[2] = true;
                                }
                                break;
                            default:
                                break;
                        }
                        if(bindPageSlider != null){
                            bindPageSlider.setCurrentPage(tabList.getSelectedTabIndex(), true);
                        }
                        break;
                    case "secondCenterTabList":
                        switch (tab.getPosition()) {
                            case 0:
                                if(worldfieldonce[0]){
                                    worldfieldonce[0] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","art");
                                    worldfieldonce[0] = true;
                                }
                                break;
                            case 1:
                                if(worldfieldonce[1]){
                                    worldfieldonce[1] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","clothe");
                                    worldfieldonce[1] = true;
                                }
                                break;
                            case 2:
                                if(worldfieldonce[2]){
                                    worldfieldonce[2] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","food");
                                    worldfieldonce[2] = true;
                                }
                                break;
                            case 3:
                                if(worldfieldonce[3]){
                                    worldfieldonce[3] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","house");
                                    worldfieldonce[3] = true;
                                }
                                break;
                            case 4:
                                if(worldfieldonce[4]){
                                    worldfieldonce[4] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","traffic");
                                    worldfieldonce[4] = true;
                                }
                                break;
                            case 5:
                                if(worldfieldonce[5]){
                                    worldfieldonce[5] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","study");
                                    worldfieldonce[5] = true;
                                }
                                break;
                            case 6:
                                if(worldfieldonce[6]){
                                    worldfieldonce[6] = false;
                                }
                                else{
                                    MyTools.DownDataWorldListInfo(MainAbilitySlice.this,"worldfield","culture");
                                    worldfieldonce[6] = true;
                                }
                                break;
                            default:
                                break;
                        }
                        if(bindPageSlider != null){
                            bindPageSlider.setCurrentPage(tabList.getSelectedTabIndex(), true);
                        }
                        break;
                    case "fourthCenterTabList":
                        switch(tab.getPosition()){
                            case 0:
                                DataCenterControl.webView.load(DataCenterControl.messageNoticeUrlString);
                                break;
                            case 1:
                                if(messageonce[0]){
                                    messageonce[0] = false;
                                }
                                else{
                                    MyTools.DownDataMessageListInfo(MainAbilitySlice.this,"messageagree");
                                    messageonce[0] = true;
                                }
                                break;
                            case 2:
                                if(messageonce[1]){
                                    messageonce[1] = false;
                                }
                                else{
                                    MyTools.DownDataMessageListInfo(MainAbilitySlice.this,"messagediscuss");
                                    messageonce[1] = true;
                                }
                                break;
                            case 3:
                                if(messageonce[2]){
                                    messageonce[2] = false;
                                }
                                else{
                                    MyTools.DownDataMessageListInfo(MainAbilitySlice.this,"messagecollect");
                                    messageonce[2] = true;
                                }
                                break;
                            default:
                                break;
                        }
                        if(bindPageSlider != null){
                            bindPageSlider.setCurrentPage(tabList.getSelectedTabIndex(), true);
                        }
                        break;
                }
            }
            @Override
            public void onUnselected(TabList.Tab tab) {
                if(tabList.getName().equals("mainBottomTablist")) {
                    tab.setBackground(null);
                }
            }
            @Override
            public void onReselected(TabList.Tab tab) {
                if(tabList.getName().equals("fourthCenterTabList") && tab.getPosition() == 0) {
                    if(DataCenterControl.webView != null){
                        DataCenterControl.webView.load(DataCenterControl.messageNoticeUrlString);
                    }
                }
            }
        });

        if(tabListName.equals("mainBottomTablist")){
            TabList.Tab tab2 = deepdl_bottomdl_tablist.getTabAt(2);
            tab2.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    if(tab2.getText().equals(tabNames[2])){
                        if(DataCenterControl.webView != null){
                            DataCenterControl.webView.setVisibility(Component.INVISIBLE);
                        }
                        surfacedl.setVisibility(Component.VISIBLE);
                        tab2.setText("❌");
                    }
                }
            });
        }
        if(tabList.getTabCount() != 0 && !tabList.getName().equals("fourthCenterTabList")){
            tabList.selectTabAt(0);
        }
        else{
            tabList.selectTabAt(1);
        }
    }
    /*------------------------------------------初始化TabList区域---------------------------------->*/

    /*<----------------------------------------初始化ListContainer区域----------------------------------*/
    public static void initListContainer(ListContainer listContainer,String listContainerName,AbilitySlice slice,int typeN,int order){
        //order:指明是那个tablist中的哪个tab
        if(listContainer == null){return;}
        listContainer.setName(listContainerName);
        LCProviderForContent lcProviderForContent = null;
        LCProviderForNormal lcProviderForNormal = null;
        switch (typeN) {
            case 0:
                switch (order) {
                    case 0:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.worlddt_listcontainer_list,slice);
                        DataCenterControl.worldDtListContainerProvider = lcProviderForContent;
                        break;
                    case 1:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.worldxm_listcontainer_list,slice);
                        DataCenterControl.worldXmListContainerProvider = lcProviderForContent;
                        break;
                    case 2:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.worldwz_listcontainer_list,slice);
                        DataCenterControl.worldWzListContainerProvider = lcProviderForContent;
                        break;
                    default:
                        break;
                }
                break;
            case 1:
                switch (order) {
                    case 0:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.art_listcontainer_list,slice);
                        DataCenterControl.artListContainerProvider = lcProviderForContent;
                        break;
                    case 1:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.clothe_listcontainer_list,slice);
                        DataCenterControl.clotheListContainerProvider = lcProviderForContent;
                        break;
                    case 2:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.food_listcontainer_list,slice);
                        DataCenterControl.foodListContainerProvider = lcProviderForContent;
                        break;
                    case 3:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.house_listcontainer_list,slice);
                        DataCenterControl.houseListContainerProvider = lcProviderForContent;
                        break;
                    case 4:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.traffic_listcontainer_list,slice);
                        DataCenterControl.trafficListContainerProvider = lcProviderForContent;
                        break;
                    case 5:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.study_listcontainer_list,slice);
                        DataCenterControl.studyListContainerProvider = lcProviderForContent;
                        break;
                    case 6:
                        lcProviderForContent = new LCProviderForContent(DataCenterControl.culture_listcontainer_list,slice);
                        DataCenterControl.cultureListContainerProvider = lcProviderForContent;
                        break;
                    default:
                        break;
                }
                break;
            case 2:
                break;
            case 3:
                switch (order) {
                    case 0:
                        break;
                    case 1:
                        lcProviderForNormal = new LCProviderForNormal(DataCenterControl.messageagree_listcontainer_list,slice);
                        DataCenterControl.messageAgreeListContainerProvider = lcProviderForNormal;
                        break;
                    case 2:
                        lcProviderForNormal = new LCProviderForNormal(DataCenterControl.messagediscuss_listcontainer_list,slice);
                        DataCenterControl.messageDiscussListContainerProvider = lcProviderForNormal;
                        break;
                    case 3:
                        lcProviderForNormal = new LCProviderForNormal(DataCenterControl.messagecollect_listcontainer_list,slice);
                        DataCenterControl.messageCollectListContainerProvider = lcProviderForNormal;
                        break;
                    default:
                        break;
                }
                break;

            case 4:
                break;
            default:
                break;
        }

        if(lcProviderForContent != null){
            listContainer.setItemProvider(lcProviderForContent);
        }
        if(lcProviderForNormal != null){
            listContainer.setItemProvider(lcProviderForNormal);
        }

        listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int i, long l) {
                Text typeText = (Text) ((DirectionalLayout)component).getComponentAt(0);
                switch(typeText.getText()){
                    case "项目":
                        slice.present(new XmDetails(),new Intent().setParam("listContainerName",listContainer.getName()).setParam("i", i));
                        break;
                    case "动态":
                    case "文章":
                        slice.present(new DtAndWzDetails(),new Intent().setParam("listContainerName",listContainer.getName()).setParam("i", i));
                        break;
                    default:
                        break;
                }
            }
        });
    }
    /*-----------------------------------------初始化ListContainer区域---------------------------------->*/

    /*<-----------------------------------------初始化MainAbilitySlice启动显示组件区域-----------------------------------*/
    private void initMASComponents(){
        //初始化启动页组件
        deepdl = (DirectionalLayout) findComponentById(ResourceTable.Id_deepdl);
        deepdl_topdl = (DirectionalLayout) findComponentById(ResourceTable.Id_deepdl_topdl);
        deepdl_centerdl = (DirectionalLayout) findComponentById(ResourceTable.Id_deepdl_centerdl);
        deepdl_bottomdl = (DirectionalLayout) findComponentById(ResourceTable.Id_deepdl_bottomdl);

        deepdl_bottomdl_tablist = (TabList) findComponentById(ResourceTable.Id_deepdl_bottomdl_tablist);

        surfacedl = (DirectionalLayout) findComponentById(ResourceTable.Id_surfacedl);
        surfacedl_writeselect = (DirectionalLayout) findComponentById(ResourceTable.Id_surfacedl_writeselect);

        dt_but = (Button) findComponentById(ResourceTable.Id_dt_but);
        xm_but = (Button) findComponentById(ResourceTable.Id_xm_but);
        wz_but = (Button) findComponentById(ResourceTable.Id_wz_but);


        surfacedl.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                surfacedl.setVisibility(Component.HIDE);
                if(DataCenterControl.webView != null){
                    DataCenterControl.webView.setVisibility(Component.VISIBLE);
                }
                TabList.Tab tab2 = deepdl_bottomdl_tablist.getTabAt(2);
                tab2.setText(bottomTabNames[2]);
            }
        });
        dt_but.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                surfacedl.getClickedListener().onClick(surfacedl);
                present(new EditDtDetailSlice(),new Intent());
            }
        });
        xm_but.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                surfacedl.getClickedListener().onClick(surfacedl);
                present(new EditXmDetailSlice(),new Intent());
            }
        });
        wz_but.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                surfacedl.getClickedListener().onClick(surfacedl);
                present(new EditWzDetailSlice(),new Intent());
            }
        });
    }
    /*------------------------------------------初始化MainAbilitySlice启动显示组件区域---------------------------------->*/

    /*<-----------------------------------------生命周期函数区域-----------------------------------*/
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        initMASComponents();
        initTabList(deepdl_bottomdl_tablist,bottomTabNames,"mainBottomTablist",null);
    }

    @Override
    protected void onActive() {
        super.onActive();
    }

    @Override
    protected void onInactive() {
        super.onInactive();
        if(toanotherslice){terminate();}
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onBackground() {
        super.onBackground();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
    /*------------------------------------------生命周期函数区域---------------------------------->*/
}
